ninab416 2.2.1
Loading...
Searching...
No Matches
ninab416.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef NINAB416_H
29#define NINAB416_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
58
63
68
73#define NINAB416_CMD_AT "AT"
74#define NINAB416_CMD_GET_MODEL_ID "AT+CGMM"
75#define NINAB416_CMD_GET_SW_VERSION "AT+CGMR"
76#define NINAB416_CMD_GET_SERIAL_NUM "AT+CGSN"
77#define NINAB416_CMD_FACTORY_RESET "AT+UFACTORY"
78#define NINAB416_CMD_REBOOT_DEVICE "AT+CPWROFF"
79#define NINAB416_CMD_BT_LOCAL_NAME "AT+UBTLN"
80#define NINAB416_CMD_CONNECT_PEER "AT+UDCP"
81#define NINAB416_CMD_WRITE_DATA "AT+UDATW"
82#define NINAB416_CMD_READ_DATA "AT+UDATR"
83#define NINAB416_CMD_CLOSE_PEER "AT+UDCPC"
84#define NINAB416_CMD_ENTER_DATA_MODE "ATO1"
85#define NINAB416_CMD_ENTER_CMD_MODE "+++"
86
91#define NINAB416_RSP_OK "OK"
92#define NINAB416_RSP_ERROR "ERROR"
93
98#define NINAB416_URC_GREETING "+STARTUP"
99#define NINAB416_URC_PEER_CONNECTED "+UUDPC:"
100#define NINAB416_URC_PEER_DISCONNECTED "+UUDPD:"
101#define NINAB416_URC_READ_SOCKET_DATA "+UUDATA:"
102
108#define NINAB416_TX_DRV_BUFFER_SIZE 200
109#define NINAB416_RX_DRV_BUFFER_SIZE 600
110 // ninab416_cmd
112
117
122
127#define NINAB416_MAP_MIKROBUS( cfg, mikrobus ) \
128 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
129 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
130 cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
131 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
132 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
133 cfg.dsr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
134 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
135 // ninab416_map // ninab416
138
143typedef struct
144{
145 // Output pins
146 digital_out_t rst;
147 digital_out_t cts;
148 digital_out_t dsr;
149
150 // Input pins
151 digital_in_t dtr;
152 digital_in_t rts;
153
154 // Modules
155 uart_t uart;
156
157 // Buffers
161
162} ninab416_t;
163
168typedef struct
169{
170 // Communication gpio pins
171 pin_name_t rx_pin;
172 pin_name_t tx_pin;
173
174 // Additional gpio pins
175 pin_name_t dtr;
176 pin_name_t rst;
177 pin_name_t cts;
178 pin_name_t dsr;
179 pin_name_t rts;
180
181 // Static variable
182 uint32_t baud_rate;
184 uart_data_bits_t data_bit;
185 uart_parity_t parity_bit;
186 uart_stop_bits_t stop_bit;
187
189
202
208
219
234
247err_t ninab416_generic_write ( ninab416_t *ctx, uint8_t *data_in, uint16_t len );
248
261err_t ninab416_generic_read ( ninab416_t *ctx, uint8_t *data_out, uint16_t len );
262
272void ninab416_set_rst_pin ( ninab416_t *ctx, uint8_t state );
273
283
293void ninab416_set_cts_pin ( ninab416_t *ctx, uint8_t state );
294
304
314void ninab416_set_dsr_pin ( ninab416_t *ctx, uint8_t state );
315
325
335void ninab416_cmd_run ( ninab416_t *ctx, uint8_t *cmd );
336
347void ninab416_cmd_set ( ninab416_t *ctx, uint8_t *cmd, uint8_t *value );
348
358void ninab416_cmd_get ( ninab416_t *ctx, uint8_t *cmd );
359
360#ifdef __cplusplus
361}
362#endif
363#endif // NINAB416_H
364 // ninab416
366
367// ------------------------------------------------------------------------ END
#define NINAB416_TX_DRV_BUFFER_SIZE
NINA-B416 driver buffer size.
Definition ninab416.h:108
#define NINAB416_RX_DRV_BUFFER_SIZE
Definition ninab416.h:109
void ninab416_cmd_set(ninab416_t *ctx, uint8_t *cmd, uint8_t *value)
NINA-B416 cmd set function.
void ninab416_set_cts_pin(ninab416_t *ctx, uint8_t state)
NINA-B416 set CTS pin function.
uint8_t ninab416_get_dtr_pin(ninab416_t *ctx)
NINA-B416 get DTR pin function.
void ninab416_set_rst_pin(ninab416_t *ctx, uint8_t state)
NINA-B416 set RST pin function.
err_t ninab416_generic_read(ninab416_t *ctx, uint8_t *data_out, uint16_t len)
NINA-B416 data reading function.
err_t ninab416_generic_write(ninab416_t *ctx, uint8_t *data_in, uint16_t len)
NINA-B416 data writing function.
void ninab416_reset_device(ninab416_t *ctx)
NINA-B416 reset device function.
err_t ninab416_init(ninab416_t *ctx, ninab416_cfg_t *cfg)
NINA-B416 initialization function.
void ninab416_cfg_setup(ninab416_cfg_t *cfg)
NINA-B416 configuration object setup function.
void ninab416_cmd_run(ninab416_t *ctx, uint8_t *cmd)
NINA-B416 cmd run function.
void ninab416_set_dsr_pin(ninab416_t *ctx, uint8_t state)
NINA-B416 set DSR pin function.
uint8_t ninab416_get_rts_pin(ninab416_t *ctx)
NINA-B416 get RTS pin function.
void ninab416_cmd_get(ninab416_t *ctx, uint8_t *cmd)
NINA-B416 cmd get function.
ninab416_return_value_t
NINA-B416 Click return value data.
Definition ninab416.h:195
@ NINAB416_ERROR_CMD
Definition ninab416.h:199
@ NINAB416_ERROR
Definition ninab416.h:197
@ NINAB416_OK
Definition ninab416.h:196
@ NINAB416_ERROR_TIMEOUT
Definition ninab416.h:198
NINA-B416 Click configuration object.
Definition ninab416.h:169
pin_name_t dtr
Definition ninab416.h:175
pin_name_t rts
Definition ninab416.h:179
uint32_t baud_rate
Definition ninab416.h:182
pin_name_t cts
Definition ninab416.h:177
bool uart_blocking
Definition ninab416.h:183
uart_data_bits_t data_bit
Definition ninab416.h:184
pin_name_t tx_pin
Definition ninab416.h:172
pin_name_t rx_pin
Definition ninab416.h:171
uart_stop_bits_t stop_bit
Definition ninab416.h:186
pin_name_t dsr
Definition ninab416.h:178
uart_parity_t parity_bit
Definition ninab416.h:185
pin_name_t rst
Definition ninab416.h:176
NINA-B416 Click context object.
Definition ninab416.h:144
digital_out_t dsr
Definition ninab416.h:148
uart_t uart
Definition ninab416.h:155
uint8_t uart_rx_buffer[NINAB416_RX_DRV_BUFFER_SIZE]
Definition ninab416.h:158
digital_in_t rts
Definition ninab416.h:152
digital_out_t rst
Definition ninab416.h:146
digital_out_t cts
Definition ninab416.h:147
digital_in_t dtr
Definition ninab416.h:151
uint8_t cmd_buffer[NINAB416_TX_DRV_BUFFER_SIZE]
Definition ninab416.h:160
uint8_t uart_tx_buffer[NINAB416_TX_DRV_BUFFER_SIZE]
Definition ninab416.h:159